import Handle from "./handle";
import { Modal } from "antd";
// import { ExclamationCircleOutlined } from "@ant-design/icons";
import { ExclamationCircleOutlined } from "@ant-design/icons";
import { removeToken } from "@/utils/token";

let tokenExpireModal = null;

/**
 * 登录过期处理器策略
 *
 */
export default class handleLoginExpire extends Handle {
  action(_, res) {
    if (tokenExpireModal === null) {
      tokenExpireModal = Modal.confirm({
        title: "提示",
        icon: <ExclamationCircleOutlined />,
        content: res.data.message,
        onOk() {
          removeToken();
          tokenExpireModal = null;
          window.location.href = "/login";
        },
      });
    }

    return Promise.reject(res.data);
  }
}
